

#include <iostream>
#include <cstring>
using namespace std;

int getAnswer(int tn[], int tn_l) {
	int a = 0;
	for (int i = 0; i < tn_l; i++) {
		if (tn[i] == 1) {
			a = (tn[i] << 1) + 1;
		} else {
			a = (tn[i] << 1) + 0;           //a=a<<1;
		}
	}
	return a;
}

int main() {
	cout << "sdfs";

	int n = 1, tn[10000000001];
	cout << n << "sdfs";
	while (n != 0) {
		cin >> n;
		memset(tn, 0, sizeof(tn));
		int cnt, s, tn_l = -1, answer;
		for (int i = n; i > 0; i /= 2) {
			tn[tn_l++] = i % 2;
		}
		for (int i = 0; i < tn_l; i++) {
			if (tn[i] == 1 and tn[i + 1] == 0) {
				s = i;
				break;
			}
		}
		tn[s + 1] = 1;
		if (s + 1 > tn_l) {
			tn_l = s + 1;
		}
		for (int i = s; i != 0; i++) {
			tn[s] = 0;
			cnt++;
		}
		for (int i = 0; i <= cnt - 1; i++) {
			tn[i] = 1;
		}
		answer = getAnswer(tn, tn_l);
		cout << answer;
	}
	return 0;
}
